<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function getWord() {
            var con = window.getSelection();
            console.log("content" + window.selectionStart, con);
        }


    </script>

    <style>
        .text {
            BORDER-BOTTOM: 0px solid;
            BORDER-LEFT: 0px solid;
            BORDER-RIGHT: 0px solid;
            BORDER-TOP: 0px solid;
            resize: none
        }

        .text:focus {
            outline-offset: 0px;
            outline: -webkit-focus-ring-color auto 0px;
        }
    </style>
</head>
<body>

<form>
    单行文本：<input type="text" value="Hello world!" onselect="getWord()"/>
    <br/><br/>
    多行文本：<textarea cols="20" rows="5" readonly class="text"
>Hello world!nihao  llawedjweweirfweii</textarea>

    <div onselect="alert('文本divdivdivd已被选中！')">dsagfdaklgfjdkjal;gjfkdslgjfkdla;gjfdkla;gjfkdla gjkldgjkdfslg;jfkdls;gj
        dkslgjfkdls;gjfkld
    </div>
</form>


<script>
    window.onload = function () {

        document.onselect = function () {

            console.log("selected...")

            var selectContent = window.getSelection().toString();

            console.log("selectContent:" + selectContent);
        }
    };
</script>
</body>
</html>